using Microsoft.EntityFrameworkCore;
using Park.Net.EFCoreEnv;
using Park.Net.IRepository;
using Park.Net.IService;
using Park.Net.Utils;
using Park.Net.Model;
using Park.Net.Service;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddDbContext<ParkDbContext>(
    option=>{
     option.UseSqlServer(builder.Configuration.GetConnectionString("Default"));
     option.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
    
    }
);


builder.Services.AddCustomService();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseAuthorization();

app.MapControllers();

app.Run();


public static class IOCExtension
{
    public static IServiceCollection AddCustomService(this IServiceCollection services)
    {
        services.AddScoped<IBaseRepository<CarPark>, CarParkRepository>();
        services.AddScoped<IBaseRepository<Feedback>, FeedbackRepository>();
        services.AddScoped<IBaseRepository<Owner>, OwnerRepository>();
        services.AddScoped<IBaseRepository<Rent>, RentRepository>();
        services.AddScoped<IBaseServices<CarPark>, CarParkService>();
        services.AddScoped<IBaseServices<Feedback>, FeedbackService>();
          services.AddScoped<IBaseServices<Rent>, RentService>();
        services.AddScoped<IBaseServices<Owner>, OwnerService>();

        return services;
    }
}